package com.linwen.excise.huaweiOJ;

/**
 * @ClassName _02分班问题
 * @Description
 * @Author lin
 * @Date 2022/6/7 下午11:49
 * @Version V1.0
 */

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 假设现在有两个班级的学生排队的时候顺序打乱了， 但是每个同学知道自己前面的同学是不是自己班上的，需要你写个程序来把两个班的同学分出来
 * 学生序号范围(0,999]
 * 如果输入不合法则打印ERROR
 * 打印时两组学生第一个学生编号小的放第一行，如果有个班是空的则放第二行打印一个空行。
 * 输入
 * 2/Y 1/N 3/N 4/Y 5/Y
 * 输出
 * 1 2
 * 3 4 5
 *
 * */
public class _02分班问题 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.nextLine();
        String[] split = str.split(" ");
        List<Student> students = new ArrayList<>(split.length);
        List<Student> class1 = new ArrayList<>();
        List<Student> class2 = new ArrayList<>();
        for (int i = 0; i < split.length; i++) {
            Student student = new Student(split[i]);
            if (!checkStudent(student)) {
                System.out.println("ERROR");
                return;
            }
            students.add(student);
        }
        // 标识当前的班级，true为class1   false为class2
        boolean flag = false;
        for (int i = 0; i < students.size(); i++) {
            Student currentStudent = students.get(i);
            if(currentStudent.beforeIsSame.equals("N")){
                flag = !flag;
            }
            if(flag){
                class1.add(currentStudent);
            }else{
                class2.add(currentStudent);
            }
        }

        for (int i = 0; i < class1.size(); i++) {
            System.out.print(class1.get(i).number+" ");
        }
        System.out.println();
        for (int i = 0; i < class2.size(); i++) {
            System.out.print(class2.get(i).number+" ");
        }

    }

    private static boolean checkStudent(Student student) {
        if(student.beforeIsSame==null){
            return false;
        }
        return true;
    }


    static class Student{
        int number;
        String beforeIsSame;
        public Student(String string){
            try{
                String[] split = string.split("/");
                int number = Integer.parseInt(split[0]);
                String beforeIsSame = split[1];
                if(number<=0||number>999){
                    throw new RuntimeException();
                }
                if(!beforeIsSame.equals("Y")&&!beforeIsSame.equals("N")){
                    throw new RuntimeException();
                }
                this.number = number;
                this.beforeIsSame = beforeIsSame;
            }catch (Exception ignored){
                this.number = 0;
                this.beforeIsSame = null;
            }
        }

        @Override
        public String toString() {
            return "Student{" +
                    "numer=" + number +
                    ", beforeIsSame='" + beforeIsSame + '\'' +
                    '}';
        }
    }

}